package com.kh.pajx.sop.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.pajx.sop.base.BaseServiceImpl;
import com.kh.pajx.sop.dao.ForeignBackDao;
import com.kh.pajx.sop.domain.ForeignBack;
import com.kh.pajx.sop.service.ForeignBackService;
@Service
@Transactional
public class ForeignBackServiceImpl extends BaseServiceImpl<ForeignBack> implements ForeignBackService {
	private ForeignBackDao foreignDao;
    @Resource
	public void setForeignDao(ForeignBackDao foreignDao) {
		this.foreignDao = foreignDao;
	}

	@Override
	public void addForeign(ForeignBack pwfi) {
		foreignDao.save(pwfi);
		
	}

	@Override
	public void updateForeign(ForeignBack pwfi) {
		foreignDao.update(pwfi);
		
	}

	@Override
	public void deleteForeign(String uuid) {
		foreignDao.delete(uuid);
		
	}

	@Override
	public List<ForeignBack> searchForeign(Map<String, String> params) {
		StringBuffer sb = new StringBuffer();
		String userId = params.get("userId");
		String appState=params.get("appState");
		String IsAppState=params.get("IsAppState");
		String appBillCode=params.get("appBillCode");
		/*try {
			if(StringUtils.isNotBlank(userId)&&!PropertyValidate.validateUUID(userId)){
				throw new Exception("申请单号输入不合法");
			}
			if(StringUtils.isNotBlank(appState)&&!"0".equals(appState)&&!"1".equals(appState)){
				throw new Exception("申请状态输入非法");
			    }
			 if(StringUtils.isNotBlank(IsAppState)&&!"0".equals(IsAppState)&&!"1".equals(IsAppState)){
					throw new Exception("申请状态输入非法");
			}
			 if(StringUtils.isNotBlank(appBillCode)&&!PropertyValidate.validateUUID(appBillCode)){
					throw new Exception("申请单号输入不合法");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		String hsSclid=params.get("hsSclid");
		sb.append("select fb from  ForeignBack fb where 1=1 ");
		if (userId != null && !"".equals(userId)) {
			sb.append(" and fb.ywSaleId ='").append(userId).append("' ");
		}
		if (appState != null && !"".equals(appState)) {
			sb.append(" and fb.appState ='").append(appState).append("' ");
		}
		if (appBillCode != null && !"".equals(appBillCode)) {
			sb.append(" and fb.appBillCode ='").append(appBillCode).append("' ");
		}
		if (hsSclid != null && !"".equals(hsSclid)) {
			sb.append(" and fb.hsSclid ='").append(hsSclid).append("' ");
		}
		if (IsAppState != null && !"".equals(IsAppState)) {
			sb.append(" and fb.appState !=").append(IsAppState).append(" ").append("and fb.appState !=0");
		}
		sb.append(" order by fb.appBillCode desc");
		return foreignDao.findList(sb.toString());
	}

	@Override
	public ForeignBack findForeignById(String id) {
		return foreignDao.getById(id);
	}
	@Override
	public List<ForeignBack> getAllForeign() {
		return foreignDao.findAll();
	}

	
}
